import Loadable from '@loadable/component';
import pMinDelay from 'p-min-delay';
import { Skeleton } from 'antd';

function Ld(loader, props = {}) {
  /**
   * 基于@loadable/component的懒加载
   * */
  return Loadable(() => pMinDelay(loader(), 300), {
    fallback: (
      <Skeleton
        active
        paragraph={{
          rows: 20,
        }}
      />
    ),
    ...props,
  });
}

function addLayout(routers, Component) {
  /**
   * 增加layout组件
   * */
  routers.forEach((v) => {
    if (v.isLayout) {
      v.element = <Component />;
    }
  });
  return routers;
}

export { addLayout, Ld };
